package com.runen.infinitemovement.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.runen.infinitemovement.App;
import com.runen.infinitemovement.Constant;
import com.runen.infinitemovement.R;
import com.runen.infinitemovement.model.entity.SportsRecordEntity;
import com.runen.infinitemovement.tool.CommonUtil;
import com.runen.rxnetlibrary.utils.TimeUtil;

public class SportsRecordAdapter extends BaseQuickAdapter<SportsRecordEntity.DataBean, BaseViewHolder> implements LoadMoreModule {
    private Context context;

    public SportsRecordAdapter(Context context) {
        super(R.layout.item_sports_record);
        this.context = context;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, SportsRecordEntity.DataBean item) {
        helper.setText(R.id.tv_time, TimeUtil.dealDateFormat(item.beginTime));
        helper.setText(R.id.tc_sports_distance, CommonUtil.Double2position(item.mileage) + "km");
        helper.setText(R.id.tv_sports_hot, CommonUtil.Double2position(item.calories) + "千卡");
        helper.setText(R.id.tv_sports_time_long, CommonUtil.Double2position(item.duration / 60) + "分钟");
        ImageView iv_img = helper.getView(R.id.iv_img);
        ImageView iv_sports_type = helper.getView(R.id.iv_sports_type);
        TextView tv_sports_type = helper.getView(R.id.tv_sports_type);
        TextView tv_zuobi = helper.getView(R.id.tv_zuobi);
        if (item.sportCheatingStatus) {
            tv_zuobi.setVisibility(View.VISIBLE);
        } else {
            tv_zuobi.setVisibility(View.GONE);
        }
        String imgUrl = String.format(Constant.IMG_SPORT_RECORD, item.sportRecordId) + "?type=mini";
//        GlideUtils.loadImage(context, imgUrl, iv_img);
        Glide.with(App.getInstance()).load(imgUrl).error(R.mipmap.ico_default_img).into(iv_img);
        switch (item.sportType) {
            case 0:
                iv_sports_type.setImageResource(R.mipmap.ico_run_circel);
                tv_sports_type.setText("跑步");
                break;
            case 1:
                iv_sports_type.setImageResource(R.mipmap.ico_riding_circel);
                tv_sports_type.setText("骑行");
                break;
            case 2:
                iv_sports_type.setImageResource(R.mipmap.ico_walking_circel);
                tv_sports_type.setText("健走");
                break;
        }
    }
}
